layui.use(['jquery','layer','table','laydate'],function(){
    var $=layui.jquery;
    var layer=layui.layer;
    var table=layui.table;
    var laydate = layui.laydate;

    //绑定时间格式
    laydate.render({
        elem: '#createDate',
        type: 'datetime',
        trigger: 'click'
    })

    getTable();

    function getTable() {
        $.ajax({
            url: '/JsLog/getProductJsLog',
            type: 'post',
            dataType: 'json',
            success: function (data) {
                demoTable(data.data);
            }
        })
    }
    search = function search() {
        var userId = $("input[name=userId]").val();
        var remark = $("input[name=remark]").val();
        var type = $("#type option:selected").text();
        var newType;
        if(type=="查看"){
            newType=5
        }else if(type=="日志"){
            newType=1
        }else if(type=="编辑"){
            newType=4
        }else if(type=="删除"){
            newType=3
        }
        var createDate = $("input[name=createDate]").val();
        getTableByCondition(userId,remark,newType,createDate);
    }

    function getTableByCondition(userId,remark,newType,createDate){
        $.ajax({
            url: '/JsLog/getProductJsLog',
            type: 'post',
            dataType: 'json',
            data: {"trueName":userId,"remark":remark,"type":newType,"createDate":createDate},
            success: function (data) {
                demoTable(data.data);
            }
        })
    }
    /*表格*/
    function demoTable(data){
        table.render({
            elem:'#demoTable',
            title:"数据列表",
            data:data,
            toolbar:'#button_ids',
            limit:10,
            width:1570,
            page:{
                layout:['count','prev','page','next','limit','skip','refresh'],
                limits:[10,20,50],
                first:"首页",
                last:"尾页",
            },
            cols:[[
                {type:"checkbox",float:"left"},
                {title:"序号",align:'center',width:100,templet:function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:"trueName",title:"管理员名称",align:'center',width:245},
                {field:"remark",title:"操作的列表",align:'center',width:245},
                {field:"createDate",title:"执行时间",align:'center',width:245},
                {field:"type",title:"操作类型",align:'center',width:245,templet:function (data) {
                    if(data.type==1){
                        return "日志"
                    }else if(data.type==3){
                        return "删除"
                    }else if(data.type==4){
                        return "修改"
                    }else if(data.type==5){
                        return "查看"
                    }
                }},
                {field:"",title:"备注",align:'center',width:243,templet:function (data) {
                    return '无内容';
                }},
                {title:"操作",align:'center',width:190,toolbar:'#button_caozuo'}
            ]]
        })
    }

    table.on('tool(demoTable)',function (obj) {
        var event = obj.event;
        if (event == "deleteTable"){
            layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
                $.ajax({
                    url: '/JsLog/deleteProductJsLog',
                    type: 'post',
                    dataType: 'json',
                    data: {'logId':obj.data.logId},
                    success: function (data) {
                        getTable();
                    }
                })
                layer.close(index);
            });
        }
    })

})